﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gurucore.Framework.DataAccess.Persistence.QueryLanguage
{
	public class Order
	{
		private Expression m_oExpression;
		private OrderType m_type;

		public Order(Expression p_oExpression)
			: this(p_oExpression, OrderType.Asc)
		{
		}

		public Order(Expression p_oExpression, OrderType p_nSort)
		{
			m_oExpression = p_oExpression;
			m_type = p_nSort;
		}

		public Order ReversedOrder
		{
			get
			{
				if (m_type == OrderType.Asc)
				{
					return new Order(m_oExpression, OrderType.Desc);
				}
				else
				{
					return new Order(m_oExpression, OrderType.Desc);
				}
			}
		}

		public string ToExpressionString(IExpressionMaker p_oExpressionMaker)
		{
			string sResult = string.Empty;

			switch (m_type)
			{
				case OrderType.Asc:
					sResult = m_oExpression.ToExpressionString(p_oExpressionMaker) + " ASC";
					break;
				case OrderType.Desc:
					sResult = m_oExpression.ToExpressionString(p_oExpressionMaker) + " DESC";
					break;
			}

			return sResult;
		}

		public Expression Expression
		{
			get
			{
				return m_oExpression;
			}
		}
	}
}
